{
  Визуальные элементы редактирования структурных схем

 TVislSchemeEditor - Редактор времени выполнения

   версия 0.1 декабрь 2010 prodg@ya.ru D.Kondakov
}
unit VislSchemeEditor;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, VislSchemeView, VislObjects;

type
  TBorderWdth = 0..MaxInt;

  { TVislSchemeEditor }

  TVislSchemeEditor = class(TCustomControl)
  private
    { Private declarations }
    FShowGrid: boolean;
    FViewOnly: boolean;
    FModified: boolean;
    FElementsBorder: TBorderWdth;
    procedure SetShowGrid(Value: boolean);
    procedure SetViewOnly(Value: boolean);
    procedure SetElementsBorder(Value: TBorderWdth);
    property Cursor;
  protected
    { Protected declarations }
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure MouseLeave; override;
    procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
    procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
    procedure Click; override;
    function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override;
    function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
    function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
    procedure Paint; override;
  public
    { Public declarations }
    procedure Undo;
    procedure Redo;
    constructor Create(TheOwner: TComponent); override;
  published
    { Published declarations }
    property Align;
    property Anchors;
    property BorderSpacing;
    property Constraints;
    property TabOrder;
    property TabStop;
    property Visible;
    property ShowGrid: boolean read FShowGrid write SetShowGrid default True;
    property ViewOnly: boolean read FViewOnly write SetViewOnly default False;
    property Modified: boolean read FModified;
    property ElementsBorder: TBorderWdth read FElementsBorder write SetElementsBorder default 3;
  end;

procedure Register;

implementation

procedure TVislSchemeEditor.SetShowGrid(Value: boolean);
begin
  FShowGrid := Value;
  Update;
end;

procedure TVislSchemeEditor.SetViewOnly(Value: boolean);
begin
  FViewOnly := Value;
end;

procedure TVislSchemeEditor.SetElementsBorder(Value: TBorderWdth);
begin
  if FElementsBorder = Value then exit;
  FElementsBorder := Value;
//  Perform(CM_BORDERCHANGED, 0, 0);
end;

procedure TVislSchemeEditor.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
  if (csDesigning in ComponentState) then
    inherited
  else begin

    inherited;
  end;
end;

procedure TVislSchemeEditor.MouseLeave;
begin
  if (csDesigning in ComponentState) then
    inherited
  else begin

    inherited;
  end;
end;

procedure TVislSchemeEditor.MouseUp(Button: TMouseButton; Shift:TShiftState; X,Y:Integer);
begin
  if (csDesigning in ComponentState) then
    inherited
  else begin

    inherited;
  end;
end;

procedure TVislSchemeEditor.MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer);
begin
  if (csDesigning in ComponentState) then
    inherited
  else begin

    inherited;
  end;
end;

procedure TVislSchemeEditor.Click;
begin
  if (csDesigning in ComponentState) then
    inherited
  else begin

    inherited;
  end;
end;

function TVislSchemeEditor.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean;
begin
  if (csDesigning in ComponentState) then
    inherited
  else begin

    inherited;
  end;
end;

function TVislSchemeEditor.DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
  if (csDesigning in ComponentState) then
    inherited
  else begin

    inherited;
  end;
end;

function TVislSchemeEditor.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
  if (csDesigning in ComponentState) then
    inherited
  else begin

    inherited;
  end;
end;

procedure TVislSchemeEditor.Paint;
begin
  if csDesigning in ComponentState then begin
    with Canvas do
    begin
      Pen.Style := psDash;
      Pen.Color:=clBlack;
      Brush.Style := bsClear;
      Brush.Color := Color;
      Rectangle(FElementsBorder, FElementsBorder, Self.Width - 1 - FElementsBorder, Self.Height - 1 - FElementsBorder);
      Line(FElementsBorder,FElementsBorder,Self.Width-1-FElementsBorder,Self.Height-1-FElementsBorder);
      Line(Self.Width-1-FElementsBorder,FElementsBorder,FElementsBorder,Self.Height-1-FElementsBorder);
    end;
    exit;
  end;
  with Canvas do begin
    Pen.Color:=clBlack;
    Brush.Style := bsClear;
    Brush.Color := Color;
    Rectangle(FElementsBorder, FElementsBorder, Self.Width - 1 - FElementsBorder, Self.Height - 1 - FElementsBorder);
    Line(FElementsBorder,FElementsBorder,Self.Width-1-FElementsBorder,Self.Height-1-FElementsBorder);
    Line(Self.Width-1-FElementsBorder,FElementsBorder,FElementsBorder,Self.Height-1-FElementsBorder);
  end;
  inherited;
end;

procedure TVislSchemeEditor.Undo;
begin

end;

procedure TVislSchemeEditor.Redo;
begin

end;

constructor TVislSchemeEditor.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  with GetControlClassDefaultSize do
    SetInitialBounds(0, 0, CX, CY);
  UseDockManager := True;
end;

procedure Register;
begin
  {$I vislschemeeditor.lrs}
  RegisterComponents('Additional',[TVislSchemeEditor]);
end;

end.
